﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Delonix_Regia_Hotel_Management_System
{
    public partial class HouseKeepingReportPage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Session["user"] == null)
                {
                    Response.Redirect("LoginPage.aspx");
                }
            }
        }

        protected void btnLogo_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("WelcomePage.aspx");
        }

        protected void btnAdmin_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("AdminMainPage.aspx");
        }

        protected void btnCheckIn_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("CheckInPage.aspx");
        }

        protected void btnCheckOut_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("CheckOutPage.aspx");
        }

        protected void btnQuery_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("QueryPage.aspx");
        }

        protected void btnBooking_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("RoomAvailabilityPage.aspx");
        }

        protected void btnRates_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("RatesPage.aspx");
        }

        protected void btnStaff_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("StaffMainPage.aspx");
        }

        protected void btnReport_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("ReportPage.aspx");
        }

        protected void btnLogout_Click(object sender, ImageClickEventArgs e)
        {
            Session["user"] = null;
            Response.Redirect("LoginPage.aspx");
        }

        protected void btnExport_Click(object sender, EventArgs e)
        {
            Response.Clear();
            Response.Buffer = true;
            Response.AddHeader("content-disposition", "attachment;filename=HouseKeepingReport.xls");
            Response.Charset = "";
            Response.ContentType = "application/vnd.ms-excel";
            System.IO.StringWriter sw = new System.IO.StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(sw);

            GridView1.AllowPaging = false;
            this.GridView1.DataBind();

            GridView1.HeaderRow.Style.Add("background-color", "black");

            foreach (TableCell tableCell in GridView1.HeaderRow.Cells)
            {
                tableCell.Style["background-color"] = "black";
            }

            foreach (GridViewRow gridViewRow in GridView1.Rows)
            {
                gridViewRow.BackColor = System.Drawing.Color.White;
                foreach (TableCell gridViewRowTableCell in gridViewRow.Cells)
                {
                    gridViewRowTableCell.Style["background-color"] = "black";
                }
            }

            GridView1.RenderControl(hw);
            //styel to format numbers to string
            string style = @"<style> .textmode{ mso-number-format:\@; } </style>";
            Response.Write(style);
            Response.Output.Write(sw.ToString());
            Response.Flush();
            Response.End();
        }

        public override void VerifyRenderingInServerForm(Control control)
        {

        }

        protected void btnExport2_Click(object sender, EventArgs e)
        {
            Response.Clear();
            Response.Buffer = true;
            Response.AddHeader("content-disposition", "attachment;filename=HouseKeepingReport.doc");
            Response.Charset = "";
            Response.ContentType = "application/vnd.ms-word";
            System.IO.StringWriter sw = new System.IO.StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(sw);

            GridView1.AllowPaging = false;
            this.GridView1.DataBind();

            GridView1.HeaderRow.Style.Add("background-color", "black");

            foreach (TableCell tableCell in GridView1.HeaderRow.Cells)
            {
                tableCell.Style["background-color"] = "black";
            }

            foreach (GridViewRow gridViewRow in GridView1.Rows)
            {
                gridViewRow.BackColor = System.Drawing.Color.White;
                foreach (TableCell gridViewRowTableCell in gridViewRow.Cells)
                {
                    gridViewRowTableCell.Style["background-color"] = "black";
                }
            }

            GridView1.RenderControl(hw);
            //styel to format numbers to string
            string style = @"<style> .textmode{ mso-number-format:\@; } </style>";
            Response.Write(style);
            Response.Output.Write(sw.ToString());
            Response.Flush();
            Response.End();
        }
    }
}